package networkLoader;

import java.util.Collection;
import java.util.HashMap;

public class VNetwork {
    private HashMap<String, VDevice> nameToDevice = new HashMap<>();

    public VDevice addDevice(String name) {
        VDevice device = new VDevice(name);
        this.nameToDevice.put(name, device);
        return device;
    }

    public VDevice getDevice(String name) {
        if (!this.nameToDevice.containsKey(name)) {
            VDevice device = new VDevice(name);
            this.nameToDevice.put(name, device);
            return device;
        }
        return this.nameToDevice.get(name);
    }

    public Collection<VDevice> getDevices() {
        return this.nameToDevice.values();
    }

    public void addLink(String device1, String device1Port, String device2, String device2Port) {
        VDevice dev1 = this.nameToDevice.get(device1);
        VPort port1 = dev1.getPort(device1Port);
        
        VDevice dev2 = this.nameToDevice.get(device2);
        VPort port2 = dev2.getPort(device2Port);
        
        port1.setPeer(port2);
        port2.setPeer(port1);
    }
}
